﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace EncodingConvertor.Source
{
    class Config
    {
        private static string keyPath = @"SoftWare\StFileEncodingConvertor";
        private static string strFileFilter = "aspx文件|*.aspx|cs文件|*.cs|asp文件|*.asp|txt文件|*.txt|css文件|*.css|js文件|*.js|jsp文件|*.jsp|php文件|*.php";
        private static int intSourceEncoding = -1;
        private static int intTargetEncoding = 0;
        private static string strBakupPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\StFec";
        private static string strShowAD = "1";


        public Config()
        {       
        }

        public static void LoadConfig()
        {
            RegistryKey RegKey;
            RegKey = Registry.LocalMachine.OpenSubKey(keyPath, true);
            try
            {
                if (RegKey == null)
                {

                    RegKey = Registry.LocalMachine.CreateSubKey(keyPath);

                    RegKey.SetValue("FileFilter", strFileFilter);
                    RegKey.SetValue("SourceEncoding", intSourceEncoding);
                    RegKey.SetValue("TargetEncoding", intTargetEncoding);
                    RegKey.SetValue("ShowAD", int.Parse(strShowAD));
                    RegKey.SetValue("BakupPath", strBakupPath);

                }
                else
                {
                    strFileFilter = RegKey.GetValue("FileFilter").ToString();
                    strBakupPath = RegKey.GetValue("BakupPath").ToString();
                    strShowAD = RegKey.GetValue("ShowAD").ToString();

                    if (!RegKey.GetValue("SourceEncoding").ToString().Equals(""))
                    {
                        intSourceEncoding = Convert.ToInt32(RegKey.GetValue("SourceEncoding").ToString());
                    }

                    if (!RegKey.GetValue("TargetEncoding").ToString().Equals(""))
                    {
                        intTargetEncoding = Convert.ToInt32(RegKey.GetValue("TargetEncoding").ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw ex;
            }
        }
        public static string Version
        {
            get
            {
                return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
        }

        public static string FILEFILTER
        {
            get
            {
                return strFileFilter;
            }
            set
            {
                strFileFilter = value;
            }
        }

        public static int SOURCEENCODING
        {
            get
            {
                return intSourceEncoding;
            }
            set
            {
                intSourceEncoding = value;
            }
        }

        public static int TARGETENCODING
        {
            get
            {
                return intTargetEncoding;
            }
            set
            {
                intTargetEncoding = value;
            }
        }

        public static string BACKUPPATH
        {
            get
            {
                return strBakupPath;
            }
            set
            {
                strBakupPath = value;
            }
        }

        public static string SHOWAD
        {
            get
            {
                return strShowAD;
            }
            set
            {
                strShowAD = value;
            }
        }

    }
}
